<!-- 右上角兼职部门下拉数据加载 liang -->
<template>
  <el-dropdown trigger="click" @command="handlechangeDept">
    <div>
      <svg-icon icon-class="changedept" class="dept-svg" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item :command="0">主部门</el-dropdown-item>
      <el-dropdown-item v-for="item of userPartDeptOptions" :key="item.partId" :command="item.partId">
        {{ item.partDeptName }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>
<script>
import { mapGetters } from 'vuex'
import { listUserPartDept } from '@/api/system/user-part-dept'
export default {
  data() {
    return {
      // 用户兼职部门
      userPartDeptOptions: []
    }
  },
  computed: {
    ...mapGetters([
      'partId'
    ])
  },
  created() {
    // this.loadUserPartDept()
  },
  methods: {
    // 获得当前用户的兼职部门
    loadUserPartDept() {
      listUserPartDept(this.partId).then(resp => {
        if (resp) {
          this.userPartDeptOptions = resp.data.rows
        } else {
          // this.msgError(resp.message)20210127
        }
      })
    },
    // 切换部门时执行的方法
    handlechangeDept(partId) {
      // 关闭所有打开的标签
      // this.$router.push(`/index?redirect=${this.$route.fullPath}`)
      // 设置菜单为空
      this.$store.commit('user/SET_MENU', [])
      this.$store.commit('user/SET_LEFT_MENU', [])
      // 设置兼职部门 partId 的值
      this.$store.commit('user/SET_PQRTID', partId)
      // 重新加载该用户的信息
      // this.$store.dispatch('user/getInfo')
      // 关闭当前页面跳转到上一个路由
      // this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews.findIndex(item => item.path === this.$route.path), 1)
      // this.$router.push(this.$store.state.tagsView.visitedViews[this.$store.state.tagsView.visitedViews.length - 1].path)
      // 关闭所有页面,跳转到首页
      this.$store.state.tagsView.visitedViews.splice(0, this.$store.state.tagsView.visitedViews.length)
      this.$router.push(`/index?redirect=${this.$route.fullPath}`)
    }
  }
}
</script>
